package com.sto.stoapp.activity.sales;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.adapter.SoleAdapter;
import com.sto.stoapp.entity.FunctionEntity;
import com.sto.stoapp.listener.StoOnItemClickListener;
import com.sto.stoapp.widget.StoHomeActivity;

import java.util.ArrayList;
import java.util.List;

/**
 * 问题件菜单
 * @author wxf
 *
 */
public class SalesProblemPieceSelectActivity extends StoHomeActivity{
	// 按键映射
    private static final int[] MAPP_TO_KEY = { R.string.problem_piece,  R.string.problem_piece_photo};
	private ListView problemFuncList;
	private SoleAdapter problemListAdapter;
	private String busiType="";
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.sto_sales_problem_piece_menu);
		Bundle extras = getIntent().getExtras();
        busiType = extras.getString("busiType");
		this.setTitleBottom(R.string.problem_piece,
		        busiType);
		
		initWidget();
	}
	
	private void initWidget() {
		problemFuncList = (ListView)findViewById(R.id.problemFunc_list);
		problemListAdapter = new SoleAdapter(this, getResourceList());
		problemFuncList.setAdapter(problemListAdapter);
		
		problemFuncList.setOnItemClickListener(new StoOnItemClickListener(this) {
			
			@Override
			public void KcOnItemClickListener(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				arg1.setSelected(true);
				TextView title = (TextView) arg1.findViewById(R.id.res_test);
				clickItemEvent(title.getText().toString());
			}
			
		});
			
	}
	
	private void clickItemEvent(String title) {
		// 问题件
		if (title.equals(getText(R.string.problem_piece))) {
			Intent intent = new Intent(this, SalesProblemPieceActivity.class);
			intent.putExtra("busiType", busiType);
//			intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
			startActivity(intent);
		}
		// 问题件拍照
		else if (title.equals(getText(R.string.problem_piece_photo))) {
			Intent intent = new Intent(this, SalesProblemPiecePhotoActivity.class);
			intent.putExtra("busiType", busiType);
			startActivity(intent);
		}else
		{
			
		}
	}
	
	private List<FunctionEntity> getResourceList() {
		List<String> resList = new ArrayList<String>();
		resList.add(getText(R.string.problem_piece).toString());
		resList.add(getText(R.string.problem_piece_photo).toString());
		
		List<FunctionEntity> functionList = new ArrayList<FunctionEntity>();
		for (String res : resList) {
			FunctionEntity entity = new FunctionEntity();
			entity.setTitle(res);
			functionList.add(entity);
		}
		return functionList;
	}


}
